package com.ouyang.Service.Impl;

import com.ouyang.Service.UserService;
import com.ouyang.form.AddUserForm;
import com.ouyang.mapper.UserMapper;
import com.ouyang.poji.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {


    @Autowired
    private UserMapper userMapper;

    public List<User> getuserlist ( ) {
        return userMapper.getuserlist();
    }

    public List<User> search ( String key, String value ) {
        if (key.equals("")) return this.userMapper.getuserlist();
        List<User> list = null;
        switch (key) {
            case "Id":
                list = userMapper.searchById(value);
                break;
            case "UserName":
                list = userMapper.searchByUserName(value);
                break;
            case "Eamil":
                list = userMapper.searchByEmail(value);
                break;
        }
        return list;
    }

    @Override
    public void adduser ( AddUserForm userForm ) {
        try {
            userMapper.adduser(userForm);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void updateuser ( User user ) {
        try {
            userMapper.updateuser(user);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void deleteuser ( String id ) {
        try {
            userMapper.deleteuser(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
